home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 2.toast / pc / sample code / quicktime / quicktimeintro / createmovie / start code / createmovie.c next >
Encoding:
C/C++ Source or Header  |  2000-10-06  |  7.1 KB  |  256 lines

  1. /*
  2.     File:        CreateMovie.c
  3.     
  4.     Contains:    QuickTime CreateMovie sample code
  5.     
  6.     Written by:    Scott Kuechle
  7.                 (based heavily on QuickTime sample code in Inside Macintosh: QuickTime)
  8.  
  9.     Copyright:    © 1998 by Apple Computer, Inc. All rights reserved
  10.     
  11.     Change History (most recent first)
  12.     
  13.           <3>         09/30/98    rtm        tweaked calls to CreateMovieFIle and AddMovieResource to create single-fork movies
  14.         <2>        09/28/98    rtm        changes for Metrowerks compiler
  15.         <1>        06/26/98    srk        first file
  16.  
  17.  
  18. */
  19.  
  20.  
  21. /************************************************************
  22. *                                                           *
  23. *    INCLUDE FILES                                          *
  24. *                                                           *
  25. *************************************************************/
  26.  
  27.  
  28. #if !defined(_MSC_VER) && _WIN32
  29.     #include <Win32Headers.mch>
  30.     #define TARGET_OS_WIN32            1
  31. #else
  32.     #include <ConditionalMacros.h>
  33. #endif
  34.  
  35. #if TARGET_OS_WIN32
  36.     #include <QTML.h>
  37.     #define    STRICT
  38.     #include <windows.h>
  39. #endif
  40.  
  41.  
  42. #include "MacTypes.h"
  43.  
  44. #include "MacMemory.h"
  45. #include "Errors.h"
  46. #include "Fonts.h"
  47. #include "QuickDraw.h"
  48. #include "Resources.h"
  49. #include "Gestalt.h"
  50. #include "FixMath.h"
  51. #include "Sound.h"
  52. #include "string.h"
  53. #include "Movies.h"
  54. #include "ImageCompression.h"
  55. #include "Script.h"
  56. #include "TextUtils.h"
  57. #include "Processes.h"
  58.  
  59. #include "CreateMovie.h"
  60. #include "QTSound.h"
  61. #include "QTVideo.h"
  62. #include "QTUtilities.h"
  63. #include "ComFramework.h"
  64.  
  65. /************************************************************
  66. *                                                           *
  67. *    FUNCTION PROTOTYPES                                    *
  68. *                                                           *
  69. *************************************************************/
  70.  
  71. #if TARGET_OS_MAC
  72.     static void Utils_Macintosh_DisplayMsg(char *msg);
  73.     static void InitMacToolbox (void);
  74. #else if TARGET_OS_WIN32
  75.     static void Utils_Win32_DisplayMsg(char *msg);
  76. #endif
  77.  
  78.  
  79.  
  80. /************************************************************
  81. *                                                           *
  82. *    CONSTANTS                                              *
  83. *                                                           *
  84. *************************************************************/
  85.  
  86. #define kMsgDialogRsrcID    129
  87. #define kMsgItemID            3
  88.  
  89. #define kPrompt                "Enter the movie file name:"
  90. #define kFileName            "MovieFile.mov"
  91.  
  92. /*
  93. Sample Player's creator type since it is the movie player 
  94. of choice. You can use your own creator type, of course.
  95. */
  96. #define kMyCreatorType        FOUR_CHAR_CODE('TVOD')
  97.  
  98.  
  99. /************************************************************
  100. *                                                           *
  101. *    FUNCTIONS                                              *
  102. *                                                           *
  103. *************************************************************/
  104.  
  105.  
  106.  
  107.  
  108. /************************************************************
  109. *                                                           *
  110. *    CheckError()                                           *
  111. *                                                           *
  112. *    Displays error message if an error occurred            *
  113. *                                                           *
  114. *************************************************************/
  115.  
  116. void CheckError(OSErr error, char *msg)
  117. {
  118.     if (error == noErr)
  119.     {
  120.         return;
  121.     }
  122.     if (strlen(msg) > 0)
  123.     {
  124.         #if TARGET_OS_MAC
  125.             Utils_Macintosh_DisplayMsg(msg);
  126.         #else if TARGET_OS_WIN32
  127.             Utils_Win32_DisplayMsg(msg);
  128.         #endif
  129.         
  130.  
  131.         ExitToShell();
  132.  
  133.     }
  134. }
  135.  
  136.  
  137. /************************************************************
  138. *                                                           *
  139. *    CreateAMovie()                                         *
  140. *                                                           *
  141. *    Creates a QuickTime movie with both a sound & video    *
  142. *    track                                                  *
  143. *                                                           *
  144. *************************************************************/
  145.  
  146. Boolean CreateAMovie (void)
  147. {
  148.     Point where = {100,100};
  149.  
  150.     Movie theMovie = nil;
  151.     FSSpec mySpec;
  152.     short resRefNum = 0;
  153.     short resId = movieInDataForkResID;
  154.     StringPtr fileName = QTUtils_ConvertCToPascalString(kFileName);
  155.     StringPtr prompt = QTUtils_ConvertCToPascalString(kPrompt);
  156.     Boolean isSelected = false;
  157.     Boolean isReplaceing = false;
  158.     OSErr err = noErr;
  159.  
  160.         QTFrame_PutFile( prompt, fileName, &mySpec, &isSelected, &isReplaceing);
  161.         if (!isSelected) goto bail;
  162.         
  163.         // Create and open the movie file, this call creates an empty movie which
  164.         // references the file, and opens the movie file with write permission.    
  165.  
  166. // Step 1.
  167. // Insert "CreateMovieFile.clp" here
  168.  
  169.         CheckError(err, "CreateMovieFile error");
  170.  
  171.         // Call our functions to create the video track and the sound track.
  172.  
  173. // Step 2.
  174. // Build CreateMyVideoTrack function in QTVideo.c
  175.         QTVideo_CreateMyVideoTrack(theMovie);
  176.         
  177. // Step 3.
  178. // Build CreateMySoundTrack function in QTSound.c
  179.         QTSound_CreateMySoundTrack(theMovie);
  180.  
  181.         // Add the movie resource to the movie file. We use movieInDataForkResID for the resID.
  182.         // This will add the movie resource to the file's data fork for a single-fork movie file
  183.         // instead of adding the resource to the file's resource fork.
  184.  
  185. // Step 4.
  186. // Insert "AddMediaResource.clp" here
  187.  
  188.         CheckError(err, "AddMovieResource error");
  189.  
  190.         if (resRefNum)
  191.         {
  192.             // Close our open movie file
  193.             CloseMovieFile (resRefNum);
  194.         }
  195.         
  196. bail:        
  197.         free(fileName);
  198.         free(prompt);
  199.         
  200.         return(QTFrame_OpenMovieInWindow(theMovie, &mySpec));
  201.  
  202.  
  203. /************************************************************
  204. *                                                           *
  205. *    FUNCTION:  Utils_Macintosh_DisplayMsg                  *
  206. *                                                           *
  207. *    PURPOSE:   Displays Macintosh error messages           *
  208. *                                                           *
  209. *************************************************************/
  210.  
  211. #if TARGET_OS_MAC
  212. static void Utils_Macintosh_DisplayMsg(char *msg)
  213. {
  214.     DialogPtr theDlog;
  215.     Handle item = NULL;
  216.     Rect box;
  217.     StringPtr theMsg = QTUtils_ConvertCToPascalString(msg);
  218.  
  219.         theDlog = GetNewDialog(kMsgDialogRsrcID, NULL, (WindowPtr)-1);
  220.         if (theDlog != NULL)
  221.         {
  222.             short itemType;
  223.             
  224.                 GetDialogItem(theDlog, kMsgItemID, &itemType, &item, &box);
  225.                 if (item != NULL)
  226.                 {
  227.                     short itemHit;
  228.                     
  229.                         SetDialogItemText(item, theMsg);
  230.                         ModalDialog(NULL, &itemHit);
  231.                         DisposeDialog(theDlog);
  232.                 }
  233.         }
  234.         
  235.         free(theMsg);
  236. }
  237. #endif
  238.  
  239. /************************************************************
  240. *                                                           *
  241. *    FUNCTION:  Utils_Win32_DisplayMsg                      *
  242. *                                                           *
  243. *    PURPOSE:   Displays error messages for Win95/NT sample *
  244. *               code                                        *
  245. *                                                           *
  246. *************************************************************/
  247.  
  248. #if TARGET_OS_WIN32
  249. static void Utils_Win32_DisplayMsg(char *msg)
  250. {
  251.  
  252.     MessageBox(NULL, msg, "", MB_OK);
  253. }
  254. #endif
  255.